
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/18/2011 16:08:18
-- Generated from EDMX file: D:\TSPGmaps\TravelManagement\TSPGMapsDB.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [TSPGMapsDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserMap]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Maps] DROP CONSTRAINT [FK_UserMap];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[Maps]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Maps];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [UserName] nvarchar(20)  NOT NULL,
    [Password] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'Maps'
CREATE TABLE [dbo].[Maps] (
    [MapId] uniqueidentifier  NOT NULL,
    [MapName] nvarchar(max)  NOT NULL,
    [MapLocation] nvarchar(max)  NOT NULL,
    [MapOwner] nvarchar(20)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [UserName] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([UserName] ASC);
GO

-- Creating primary key on [MapId] in table 'Maps'
ALTER TABLE [dbo].[Maps]
ADD CONSTRAINT [PK_Maps]
    PRIMARY KEY CLUSTERED ([MapId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [MapOwner] in table 'Maps'
ALTER TABLE [dbo].[Maps]
ADD CONSTRAINT [FK_UserMap]
    FOREIGN KEY ([MapOwner])
    REFERENCES [dbo].[Users]
        ([UserName])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserMap'
CREATE INDEX [IX_FK_UserMap]
ON [dbo].[Maps]
    ([MapOwner]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------